const path = require('path');
const express = require('express')
const app = express();
app.use(express.static(path.join(__dirname, 'public')));
const server = require('http').createServer(app);
const io = require("socket.io")(server);

//https://socket.io/docs/v4/broadcasting-events/
//todo Please note that broadcasting is a server-only feature.
io.on("connection", socket => {
  socket.join('room1');
  socket.join('room2');
  socket.join('room3');

  io.to('room1').to('room2').to('room3').emit('all', 'hello'); //如果一个用户出现在多个房间, 该用户只会接受到一次消息
});

server.listen(3000);

